$file = $ARGV[0];
chomp($file);
$file1 = $ARGV[1];
chomp($file1);
open(WRBUFF,">$file1");
open(TBUFF,$file);
while($tline = <TBUFF>)
{
        chomp($tline);
        @tp_array = split(/\s/,$tline);
        @array_tped_snps = ();
	$num_tped =0;
	@tp_array1 = @tp_array ;
	shift(@tp_array1);
	shift(@tp_array1);
	shift(@tp_array1);
	shift(@tp_array1);
	$tline1 = join("",@tp_array1);
	@tp_array1=();
        	if($tline1 =~ m/A/)
                {
                        $array_tped_snps[$num_tped] = "A";
                        $num_tped++;
                }
                if($tline1 =~ m/C/)
                {
                        $array_tped_snps[$num_tped] = "C";
                        $num_tped++;
                }
                if($tline1 =~ m/G/)
                {
                        $array_tped_snps[$num_tped] = "G";
                        $num_tped++;
                }
                if($tline1 =~ m/T/)
                {
                        $array_tped_snps[$num_tped] = "T";
                        $num_tped++;
                }
                if($num_tped == 1)
                {
                        $tped_snp1 = $array_tped_snps[0];
			$tped_snp2 = "-";
                }
		elsif($num_tped ==0)
		{
				$tped_snp1 = "-";
				$tped_snp2 = "-";
		}
                else
                {
                         $tped_snp1 = $array_tped_snps[0];
                         $tped_snp2 = $array_tped_snps[1];
                }
		@mainar=();
		#added code to replace X,Y and M from 23,24 and 26
		if( $tp_array[0] =~ m/chr/)
		{
			$tp_array[0] =~ s/chr//g;
		}
		if( $tp_array[0] == 23 || $tp_array[0] == 24|| $tp_array[0] == 26)
		{
			$tp_array[0] =~ s/23/X/g;
			$tp_array[0] =~ s/24/Y/g;
			$tp_array[0] =~ s/26/M/g;
		}
		else
		{
			$tp_array[0] =$tp_array[0]+1-1;
		}
		push(@mainar,$tp_array[0]);
		push(@mainar,$tp_array[1]);
		push(@mainar,$tp_array[2]);
		push(@mainar,$tp_array[3]);	
		push(@mainar,$tped_snp1);
		push(@mainar,$tped_snp2);
                for($g=4;$g<@tp_array;$g++)
                {
                        $ssnp1 = $tp_array[$g];
                        $g++;
                        $ssnp2 = $tp_array[$g];
                        if($ssnp1 eq $tped_snp1 && $ssnp2  eq $tped_snp1)
                        {
				push(@mainar,1);
				push(@mainar,0);
                        }
                        elsif($ssnp1 eq $tped_snp2 && $ssnp2  eq $tped_snp2)
                        {
				push(@mainar,0);
				push(@mainar,0);
                        }
			elsif($ssnp1 eq "0" && $ssnp2  eq "0")
			{
				push(@mainar,'-');
				push(@mainar,'-');
			}
                        else
			{
				push(@mainar,0);
                                push(@mainar,1);
                        }
                }
		$line = join(" ",@mainar);
		if($num_tped != 0)
		{
			print WRBUFF $line."\n";
		}
                $numm_count++;
}
                   
